package com.duan.controller;


import com.duan.pojo.Result;
import com.duan.pojo.User;
import com.duan.utils.JWTUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.UUID;

/**
 * @author db
 * @version 1.0
 * @description LoginController
 * @since 2023/12/19
 */
@RestController
@Slf4j
public class LoginController {

    @PostMapping("/login")
    public Result login(@RequestBody User user){
        log.info("这是正常日志");
        if(!"admin".equals(user.getUsername()) && !"123456".equals(user.getPassword())){
            return Result.error("登陆失败");
        }else{
            HashMap<String, Object> map = new HashMap<>();
            map.put("id", UUID.randomUUID().toString());

            // 生成token
            String token = JWTUtils.generateJwt(map);
            return Result.success(token);
        }
    }

    @PostMapping("/getUser")
    public Result getUserById(String userId){
        User user = new User();
        user.setUsername("cxykk");
        user.setPassword("123456");
        log.info("getUser方法");

        return Result.success(user);
    }
}
